package com.m1book.site;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

import com.m1book.domain.auth.MiserDetails;
import com.m1book.domain.user.Miser;

public class Utilities {
	
	/**
	 * 后台设置指定用户为登录状态。此方法会在用户注册成功后被调用，以使注册成功的用户可以立即访问网站。
	 * @param miser 指定用户
	 */
	public static void setMiserLogin(Miser miser) {
		UserDetails userDetails = new MiserDetails(miser);
		UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, miser.getPassword(), userDetails.getAuthorities());
		SecurityContextHolder.getContext().setAuthentication(authentication);
	}

}
